package com.huike.web.controller.business;

import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.dto.TbBusinessTrackRecordDTO;
import com.huike.business.service.TbBusinessTrackRecordService;
import com.huike.common.result.Result;
import com.huike.common.utils.bean.BeanUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
// import net.sf.cglib.core.Local;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Controller
 * @date 2023-04-28
 */
@Slf4j
@RestController
@RequestMapping("/business/record")
@RequiredArgsConstructor
public class TbBusinessTrackRecordController {
    private final TbBusinessTrackRecordService tbBusinessTrackRecordService;

    @PostMapping
    public Result<String> add(@RequestBody TbBusinessTrackRecordDTO tbBusinessTrackRecordDTO){
        log.info(tbBusinessTrackRecordDTO.toString());
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyBeanProp(tbBusinessTrackRecord , tbBusinessTrackRecordDTO);
        tbBusinessTrackRecord.setCreateTime(LocalDateTime.now().toString());
        tbBusinessTrackRecord.setNextTime(LocalDateTime.now().toString());
        tbBusinessTrackRecordService.save(tbBusinessTrackRecord);
        return Result.success("添加成功");
    }

    @GetMapping("/list")
    public Result<List<TbBusinessTrackRecord>> getList(Long businessId){
        List<TbBusinessTrackRecord> tbBusinessTrackRecords = tbBusinessTrackRecordService.getList(businessId);
        return Result.success(tbBusinessTrackRecords);
    }

}
